/*
	Copyright (C) 2010 Salil Bhagurkar

	This file is part of k3

	k3 is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	k3 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with k3.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef BUFFER_H_
#define BUFFER_H_

struct buffer {
	void *data;
	u32 alloc_len; //Currently allocated length
	u32 len; //Current length
};

int buffer_write(struct buffer *buf, struct buffer *src, u32 offset, u32 len);
int buffer_write_data(struct buffer *buf, void *data, u32 offset, u32 len);
int buffer_read(struct buffer *buf, struct buffer *dst, u32 offset, u32 len);
int buffer_read_data(struct buffer *buf, void *data, u32 offset, u32 len);
struct buffer *buffer_create(u32 size);
struct buffer *buffer_from_string(char *str);
char *buffer_to_string(struct buffer *buf);
void buffer_init(struct buffer *buf, void *data, u32 len, u32 alloc_len);
int buffer_free(struct buffer *buf);
struct buffer *buffer_duplicate(struct buffer *buf);
int buffer_compare(struct buffer *buf, struct buffer *buf1);
int buffer_compare_string(struct buffer *buf, const char *str);
int buffer_append(struct buffer *buf, struct buffer *buf1);
int buffer_append_data(struct buffer *buf, void *data, u32 len);

#endif /* BUFFER_H_ */
